package com.pb.infra.oth.entity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TreeVO {

  @JsonSerialize(using = ToStringSerializer.class)
  @ExcelIgnore
  public Object id;

  @JsonSerialize(using = ToStringSerializer.class)
  @ExcelIgnore
  public Object parentId;
  @JsonSerialize(using = ToStringSerializer.class)
  @ExcelIgnore
  public Integer level;

  @JsonInclude(value= JsonInclude.Include.NON_EMPTY)
  @ExcelIgnore
  public List<TreeVO> children = new ArrayList<>();

  public void add(TreeVO node) {
    children.add(node);
  }

  public TreeVO(Object id, Object parentId) {
    this.id = id;
    this.parentId = parentId;
  }

  public TreeVO(Object id, Object parentId, Integer level) {
    this.id = id;
    this.parentId = parentId;
    this.level =level;
  }
}